angular.module("module.qrcodeDesk",[])
    .config(['$stateProvider',function ($stateProvider) {
        $stateProvider
            .state('home.qrcodeDesk',{
                url:"/qrcodeDesk",
                templateUrl:"qrcodeDesk/qrcodeDesk.html",
                controller:'QrcodeDeskController',
                controllerAs:'vm'
            })
    }])
    .controller('QrcodeDeskController',[function () {
        var vm=this;
    //生成二维码
        $('.submit').click(function() {
            var roomId = $.trim($('input[name=roomId]').val());
            if (roomId == '') return toast('请填写您的包厢号');
            $.getJSON('qrcodeDownAjax', {roomId:roomId,shopId:shopId}, function(res){
                if (!res.succeed) return winAlert({body:res.message});
                console.log(res.data);
//            重置id为frm的元素
                document.querySelector('#frm').reset();
                winAlert({
                    title:roomId+'-二维码',
                    body:'<a style="margin:0 auto;text-align:center;display:block;" download="'+res.data.qrcode+'" href="'+res.data.qrcode+'" id="qrcode">' +
                    '<img src="'+res.data.qrcode+'" width="320" height="320" />' +
                    '</a>',
                    btn:'下载',
                    cancel:'取消',
                    fun:function(){
                        var a = document.createElement('a');
                        a.download=res.data.qrcode;
                        a.href=res.data.qrcode;
                        a.click();
                        return true;
                    }});
            });
            return false;
        });
    }]);